package org.thanos.iot.controller;

import org.apache.shiro.authc.ExpiredCredentialsException;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authz.UnauthenticatedException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.thanos.iot.util.response.CommonResult;

import javax.servlet.http.HttpServletResponse;

@RestControllerAdvice
@Order(value = Ordered.HIGHEST_PRECEDENCE)
public class BaseController {

    @ExceptionHandler(value = UnknownAccountException.class)
    public void handleUnknownAccountException(HttpServletResponse response) {
        response.setStatus(HttpStatus.FORBIDDEN.value());
    }

    @ExceptionHandler(value = IncorrectCredentialsException.class)
    public void handleIncorrectCredentialsException(HttpServletResponse response) {
        response.setStatus(HttpStatus.FORBIDDEN.value());
    }

    @ExceptionHandler(value = UnauthenticatedException.class)
    public void handleUnauthenticatedException(HttpServletResponse response) {
        response.setStatus(HttpStatus.FORBIDDEN.value());
    }

    @ExceptionHandler(value = ExpiredCredentialsException.class)
    public void handleExpiredCredentialsException(HttpServletResponse response) {
        response.setStatus(HttpStatus.FORBIDDEN.value());
    }

    @ExceptionHandler(value = UnauthorizedException.class)
    public void handleUnauthorizedException(HttpServletResponse response) {
        response.setStatus(HttpStatus.FORBIDDEN.value());
    }

}
